package com.example.main;

import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyDrawerAdapter extends BaseAdapter {

	private List<MenuBean> list;
	private Context context;

	public MyDrawerAdapter(Context context, List<MenuBean> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint({ "NewApi", "InflateParams" })
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.drawer_item_layout, null);
			holder = new Holder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		MenuBean bean = list.get(position);
		holder.drawer_item_textView.setText(bean.getItem());
		holder.draw_item_imageView.setBackgroundResource(bean.getImage());
		return convertView;
	}

	public class Holder {

		private ImageView draw_item_imageView;
		private TextView drawer_item_textView;

		public Holder(View view) {
			draw_item_imageView = (ImageView) view.findViewById(R.id.draw_item_imageView);
			drawer_item_textView = (TextView) view.findViewById(R.id.drawer_item_textView);
		}
	}
}
